package com.dunshanasync.controller;

import com.dunshanasync.service.AsyncService;
import com.dunshanasync.service.IndexSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @description: 异步请求
 * @author: 李文
 * @create: 2021-05-08 20:41
 **/
@Controller
public class AsyncController {

    @Autowired
    AsyncService asyncService;

    @Autowired
    IndexSevice indexSevice;

    @GetMapping("/api/async")
    @ResponseBody
    public Object apiAsync(String data) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        HashMap<String, Object> map = new HashMap<>();
        map.put("数据", "数据已经提交，请查询后台数据");
        asyncService.asyncQuery(data);
        map.put("date", sdf.format(new Date()));
        return map;
    }

    @GetMapping("/http")
    @ResponseBody
    public Object MqIndex(HttpServletRequest request) {
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, Object> page = indexSevice.select();
        map.put("ok", "学习");
        map.put("data", page);
        return map;
    }

}

